#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e3 + 10, INF = 0x3f3f3f3f;

int n, m, x, y;
vector<int> g[N];
vector<int> ans;
int vis[N], flag = 0;

void dfs(int u)
{
    if (flag) return;
    if (u == y) {
        for (int it : ans) cout << it << ' ';cout << '\n';
        flag = 1;
        return;
    }
    for (int v : g[u]) {
        if (vis[v] || flag) continue;
        ans.push_back(v);
        vis[v] = 1;
        dfs(v);
        ans.pop_back();
    }
}

void solve()
{
    cin >> n >> m >> x >> y;
    for (int i = 1;i <= m;i++) {
        int a, b;cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 1;i <= n;i++) sort(g[i].begin(), g[i].end());

    ans.push_back(x);
    vis[x] = 1;
    dfs(x);

    for (int i = 1;i <= n;i++) g[i].clear();
    ans.clear();
    memset(vis, 0, sizeof vis);
    flag = 0;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}